﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using ScheduleMaker.DB.Domain;
using ScheduleMaker.DB.Domain.Core;

namespace ScheduleMaker.DB.CoreDAO
{
    public class CategoryDAO : CoreAbstractDAO<Category>
    {
        private AdapterAbstractDAO<Category, CategoryUniversity> wrappedAbstractDAOUniversity;
        private CategoryDAOUniversity wrappedDAOUniversity;

        public CategoryDAO(CategoryDAOUniversity wrappedDAOUniversity)
        {
            this.wrappedDAOUniversity = wrappedDAOUniversity;
            this.wrappedAbstractDAOUniversity =
                new AdapterAbstractDAO<Category, CategoryUniversity>((AbstractDAO<CategoryUniversity>)wrappedDAOUniversity);
        }

        public override void update(Category entity)
        {
            if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.update(entity);
            }
            else
            {
                throw new NotImplementedException("Wrapped CategoryDAOUniversity is not initialized");
            }
        }

        public override void save(Category entity)
        {
            if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.save(entity);
            }
            else
            {
                throw new NotImplementedException("Wrapped CategoryDAOUniversity is not initialized");
            }
        }

        public override void saveOrUpdate(Category entity)
        {
            if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.saveOrUpdate(entity);
            }
            else
            {
                throw new NotImplementedException("Wrapped CategoryDAOUniversity is not initialized");
            }
        }

        public override void delete(Category entity)
        {
            if (wrappedDAOUniversity != null)
            {
                wrappedAbstractDAOUniversity.delete(entity);
            }
            else
            {
                throw new NotImplementedException("Wrapped CategoryDAOUniversity is not initialized");
            }
        }

        public override Category getById(int id)
        {
            Category entity;
            if (wrappedDAOUniversity != null)
            {
                entity = wrappedAbstractDAOUniversity.getById(id);
            }
            else
            {
                throw new NotImplementedException("Wrapped CategoryDAOUniversity is not initialized");
            }

            return entity;
        }

        public override IList<Category> getAll()
        {
            IList<Category> records;
            if (wrappedDAOUniversity != null)
            {
                records = wrappedAbstractDAOUniversity.getAll();
            }
            else
            {
                throw new NotImplementedException("Wrapped CategoryDAOUniversity is not initialized");
            }

            return records;
        }
    }
}
